<?php
header('Content-type: text/html; charset=utf-8');
require_once '../function/protectScript.php';
require_once '../function/displayContentArray.php';

if(isset($_POST)){
	$sDirectory = $_POST['directory'];
	displayContentArray('$_POST', $_POST);
}else{
	$sDirectory = '/ays/';
}

require_once '../model/SourceEditorModel.php';
$asaDirectoryContent = SourceEditorModel::listCurrentDirectory();

$oEditorInstance = new SourceEditorModel(array('sCurrentDirectory' => $sDirectory));

echo '<ul>';
foreach($asaDirectoryContent['aisDirectoryInfos'] AS $sDirectoryName){
	if($sDirectoryName == '.'){
		$explorerRowContent = '<li id="'.$sDirectoryName.'">
			<img src="public/image/folder.gif" alt="folder" />
				'.$sDirectoryName.'
		</li>';
	}else{
		$explorerRowContent = '<li id="'.$sDirectoryName.'">
			<img src="public/image/folder.gif" alt="folder" />
			<a href="#'.$sDirectoryName.'" onClick="javascript:displayDirectory(\''.$sDirectoryName.'\');">
				'.$sDirectoryName.'
			</a>
		</li>';
	}
	echo $explorerRowContent;
}

foreach($asaDirectoryContent['aiassFilesInfos'] AS $iFile){
	switch($iFile['sExtensionFile']){
		case 'html':
		case 'xhtml':
		case 'phtml':
			$sImage = 'page_html.gif';
			break;

		case 'php':
			$sImage = 'page_php.gif';
			break;

		case 'java':
			$sImage = 'page_java.gif';
			break;

		case 'xml':
		case 'xsl':
		case 'dtd':
		case 'js':
			$sImage = 'page_script.gif';
			break;

		default:
			$sImage = 'page_text.gif';
			break;
	}
	echo '
		<li>
			<img src="public/image/'.$sImage.'" alt="file" />
			<a href="voirfichier.php?f='.$iFile['sCompleteNameFile'].'&amp;langage='.$iFile['sExtensionFile'].'">
				'.$iFile['sCompleteNameFile'].'
			</a>
		</li>'
	;
}
echo '</ul>';